<?php

/**
 * Form for allocate child with parents
 */

class Application_Form_AllocateParent extends Zend_Form_SubForm
{
    public function init()
    {
	$this->setMethod('post');
	
	//list all Parent from db into an array for multiOptions
	$m = new Model_Parent;
	$parent = $m->listAllParent();

	//default array for no selection
	$default_value = array( NULL => '');
	
	// Element Parent 1 (must selection)
	$this->addElement('select', 'parent_1_id', array(
	    'label' => 'Elternteil 1:',
	    'required' => true,
	    'multiOptions' => $default_value + $this->createSelectFildsFromParents()
	));
	// Element Parent 2
	$this->addElement('select', 'parent_2_id', array(
	    'label' => 'Elternteil 2:',
	    'required' => false,
	    'multiOptions' => $default_value + $this->createSelectFildsFromParents()
	));
	 
	}  
	
   /**
     * Converts a child array to select fields
     */
    function createSelectFildsFromParents()
    {
	$modelParents = new Model_Parent;
	$parents = $modelParents->listAll();

	$selectParents = array();
	foreach ($parents as $parent)
	{
	    $selectParents[$parent['id']] = $parent['surname'] . ", " . $parent['forename'];
	}
	return $selectParents;
    }
	
  
}
